package org.javaboy.vhr.controller.personnel;

import org.javaboy.vhr.model.Resign;
import org.javaboy.vhr.model.RespBean;
import org.javaboy.vhr.model.RespPageBean;
import org.javaboy.vhr.service.ResignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resign")
public class ResignController {
    @Autowired
    ResignService resignService;

    /**
     * 通过
     * @param page
     * @param size
     * @param keywords
     * @return
     */
    @GetMapping("/")
    public RespPageBean getAllResigns(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer size,
                                    @RequestParam(defaultValue = "") String keywords) {
        return resignService.getAllResigns(page, size, keywords);
    }

    @GetMapping("/{id}")
    public Resign getResignById(@PathVariable Integer id) {
        return resignService.getResignById(id);
    }

    /**
     * 通过
     * @param resign
     * @return
     */
    @PutMapping("/updateStatus")
    public RespBean updateResignStatus(@RequestBody Resign resign) {
        if (resignService.updateResignStatus(resign)) {
            return RespBean.ok("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

//    @PutMapping("/{id}/approve")
//    public RespBean approveResign(@PathVariable Integer id) {
//        if (resignService.updateResignStatus(id, "已批准")) {
//            return RespBean.ok("离职申请已批准！");
//        }
//        return RespBean.error("审核操作失败！");
//    }

//    @PutMapping("/{id}/reject")
//    public RespBean rejectResign(@PathVariable Integer id) {
//        if (resignService.updateResignStatus(id, "已拒绝")) {
//            return RespBean.ok("离职申请已拒绝！");
//        }
//        return RespBean.error("审核操作失败！");
//    }

    /**
     * 测试通过
     * @param resign
     * @return
     */
    @PostMapping("/")
    public RespBean addResign(@RequestBody Resign resign) {
        resign.setStatus("待审核");
        resign.setIsDelete(0);
        if (resignService.addResign(resign)) {
            return RespBean.ok("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    /**
     * 测试通过
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public RespBean deleteResign(@PathVariable Integer id) {
        if (resignService.deleteResign(id)) {
            return RespBean.ok("删除成功！");
        }
        return RespBean.error("删除失败！");
    }
}
